<?php

namespace app\admin\controller;
use think\facade\Config;
use think\Response;
use think\facade\Request;


abstract class Base
{
    //页数
    protected $page;

    //分页条数
    protected $pageSize;

    public function __construct()
    {
        //助手：request()->param()
        $this->page = (int)Request::param('page');
        //也可以用助手：config('app.page_size')，省去 use;
        $this->pageSize = (int)Request::param('page_size', Config::get('app.page_size'));
    }
    protected function create($data, string $msg = '', int $code = 200, $type = 'json'):Response
    {
        //返回 api 结果
        $result = [
            //状态码
            'code' => $code,
            //自定义消息
            'msg' => $msg,
            //数据返回
            'data' => $data
        ];
        //将数据返回成指定格式，默认 json
        return Response::create($result, $type);
    }
}